package com.tcm.entity.resp;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @author Guqier
 * @version 1.0
 * @date 2023/9/15 15:07
 */
@Data
@Accessors(chain = true)
public class Message implements Serializable {

    /**
     * 请求命令
     */
    private String code;

    /**
     * 消息
     */
    private String msg;

    /**
     * 数据
     */
    private Object data;

    /**
     * 序列化为JSON
     * @return JSON格式字符串
     * @throws JsonProcessingException 序列化异常
     */
    public String toJson() throws JsonProcessingException {
        return new ObjectMapper().writeValueAsString(this);
    }

}
